﻿using Microsoft.Office.Interop.Excel;
using System;
using System.Windows.Forms;
using WinForm = System.Windows.Forms;

namespace VSTODemo
{
    public partial class ClipBoardPro : UserControl
    {
        public ClipBoardPro()
        {
            InitializeComponent();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            string content = ThisAddIn.ExcelApp.ActiveCell.Value;

            if (lstContent.FindStringExact(content) == WinForm.ListBox.NoMatches) {
                lstContent.Items.Add(content);
            }
        }

        private void btnCopy_Click(object sender, EventArgs e)
        {
            if (lstContent.SelectedIndex != -1) {
                foreach(Range cell in ThisAddIn.ExcelApp.Selection) {
                    cell.Value = lstContent.Text;
                }                
            }
        }

        private void btnClearAll_Click(object sender, EventArgs e) {
            lstContent.Items.Clear();
        }

        private void btnClearCurrent_Click(object sender, EventArgs e) {
            lstContent.Items.RemoveAt(lstContent.SelectedIndex);
        }
    }
}
